package com.example.rabbitspringamqp.customer;

import com.example.rabbitspringamqp.dto.OrderDTO;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author haitao
 * @date 2021/7/26 10:26 上午
 */
@Service
@Slf4j
public class RabbitReceiver {


    /**
     * 这里测试多个消费者超过SimpleListenerMessageContainer
     *
     * */
    @RabbitListener(queues = "test_direct_queue")
    public void onDirectMessage1(@Payload OrderDTO orderDTO, Channel channel, @Headers Map<String, Object> headers){

        System.out.println("消费者1消费消息：" + orderDTO);
    }


    @RabbitListener(queues = "test_direct_queue")
    public void onDirectMessage2(@Payload OrderDTO orderDTO, Channel channel, @Headers Map<String, Object> headers){

        System.out.println("消费者1消费消息：" + orderDTO);
        
    }


    @RabbitListener(queues = "test_direct_queue")
    public void onDirectMessage3(@Payload OrderDTO orderDTO, Channel channel, @Headers Map<String, Object> headers){

        System.out.println("消费者3消费消息：" + orderDTO);
    }

    /**
     * 这里测试多个消费者超过SimpleListenerMessageContainer
     *
     * */
    @RabbitListener(queues = "test_direct_queue")
    public void onDirectMessage4(@Payload OrderDTO orderDTO, Channel channel, @Headers Map<String, Object> headers){

        System.out.println("消费者4消费消息：" + orderDTO);
    }

    /**
     * 这里测试多个消费者超过SimpleListenerMessageContainer
     *
     * */
    @RabbitListener(queues = "test_direct_queue")
    public void onDirectMessage5(@Payload OrderDTO orderDTO, Channel channel, @Headers Map<String, Object> headers){

        System.out.println("消费者5消费消息：" + orderDTO);
    }

}
